package com.tengju.bff.interfaces.login.assembler;


import com.tengju.user.application.login.dto.LogoutDTO;
import com.tengju.user.domain.model.login.LogoutInfo;
import com.tengju.user.domain.model.login.UserType;
import com.tengju.user.domain.model.user.StaffId;
import com.tengju.user.domain.model.user.UserId;
import com.tengju.user.domain.shared.AESUtil;
import com.tengju.user.domain.shared.Constant;

/**
 * @author wuziyang
 */
public class UserAccountAssembler {


    public static LogoutInfo dtoToModel(LogoutDTO logoutDTO,String token) throws Exception {

        StaffId staffId = null;
        UserId userId = null;

        if (logoutDTO.getUserType().equals(UserType.USER.getVal())) {
            userId = new UserId(Long.parseLong(AESUtil.decrypt(Constant.USERID_ENCRYPT_KEY,logoutDTO.getUserId())));
        } else if (logoutDTO.getUserType().equals(UserType.STAFF.getVal())) {
            staffId = new StaffId(Long.parseLong(AESUtil.decrypt(Constant.USERID_ENCRYPT_KEY,logoutDTO.getUserId())));
        }

        return new LogoutInfo(
                token,
                userId,staffId,
                UserType.fromVal(logoutDTO.getUserType()));

    }
}
